package nessie;

import java.awt.Color;

/**
 * based on http://en.wikipedia.org/wiki/List_of_video_game_console_palettes#NES
 * this class holds and handles the color palette the emulator uses. pretty straight forward.
 */
public class Palette {
//TODO:check http://nesdev.parodius.com/pal.txt

    private static final int RGB_ARRAY[][] = {
        {124, 124, 124}, {0, 0, 252}, {0, 0, 188}, {68, 40, 188},
        {148, 0, 132}, {168, 0, 32}, {168, 16, 0}, {136, 20, 0},
        {80, 48, 0}, {0, 120, 0}, {0, 104, 0}, {0, 88, 0},
        {0, 64, 88}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
        //
        {188, 188, 188}, {0, 120, 248}, {0, 88, 248}, {104, 68, 252},
        {216, 0, 204}, {228, 0, 88}, {248, 56, 0}, {228, 92, 16},
        {172, 124, 0}, {0, 184, 0}, {0, 168, 0}, {0, 168, 68},
        {0, 136, 136}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
        //
        {248, 248, 248}, {60, 188, 252}, {104, 136, 252}, {152, 120, 248},
        {248, 120, 248}, {248, 88, 152}, {248, 120, 88}, {252, 160, 68},
        {248, 184, 0}, {184, 248, 24}, {88, 216, 84}, {88, 248, 152},
        {0, 232, 216}, {120, 120, 120}, {0, 0, 0}, {0, 0, 0},
        //
        {252, 252, 252}, {164, 228, 252}, {184, 184, 248}, {216, 184, 248},
        {248, 184, 248}, {248, 164, 192}, {240, 208, 176}, {252, 224, 168},
        {248, 216, 120}, {216, 248, 120}, {184, 248, 184}, {184, 248, 216},
        {0, 252, 252}, {216, 216, 216}, {0, 0, 0}, {0, 0, 0}};
    private static final Color COLOR_ARRAY[] = new Color[RGB_ARRAY.length];
    private static final int RGB_COLOR_ARRAY[] = new int[RGB_ARRAY.length];

    private Palette() {
    }

    /***/
    public static void init() {
        int r, g, b;
        //init rgbArray
        for (int a = 0; a < RGB_ARRAY.length; a++) {
            r = RGB_ARRAY[a][0];
            g = RGB_ARRAY[a][1];
            b = RGB_ARRAY[a][2];
            COLOR_ARRAY[a] = new Color(r, g, b);
            RGB_COLOR_ARRAY[a] = new Color(r, g, b).getRGB();
        }
    }

    /**looks up the equivalent RGB value that corresponds to the NES palette code.*/
    public static int getColorRGBByCode(int code) {
        return RGB_COLOR_ARRAY[code];
    }
}
